﻿using System;
using COM.DTO;
using NHibernate;
using COM.Logging;
using NHibernate.Criterion;

namespace DAL.DAO
{
    class OrderDAO
    {
        public static void Add(COM.DTO.Order order)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(order);
                    transaction.Commit();
                }
            }
        }
        public static void Update(COM.DTO.Order order)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Update(order);
                    transaction.Commit();
                }
            }
        }

        public static void Remove(COM.DTO.Order order)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(order);
                    transaction.Commit();
                }
            }
        }

        public static COM.DTO.Order GetOrderByOrderId(String orderId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
                return session.Get<COM.DTO.Order>(orderId);
        }
        
    }
}
